#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QFutureWatcher>
#include "ftpdatamodel.h"

class QListWidgetItem;
class FtpClient;

template <typename T> class QFuture;
QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    
    void on_getRemoteDirBtn_clicked();
    void on_batchDownBtn_clicked();


    // 上传
    void on_uploadBtn_clicked();
    // 获取本地目录
    void on_getLocalDirBtn_clicked();
    // 本地目录的双击事件
    void on_localListWidgetDir_itemDoubleClicked(QListWidgetItem* item);
    void on_remoteListWidgetDir_itemDoubleClicked(QListWidgetItem* item);


    void onUploadProgress(const QString& fileName, int progress);
    void onUploadFinished(const QString& fileName, bool success);
    void onUploadError(const QString& fileName, const QString& errorMessage);

    // 获取远程目录
    void onDirectoryListingReady(const QList<Ftp::FileInfo>& fileList);
    void onDirectoryListingError(const QString& errorMessage);

    void onDownloadFinshed();
    void onDownloadProgress(const QString& fileName, int progress);
private:
    Ui::MainWindow *ui;
    FtpClient* m_ftpClient;
    void manageUploadTask(QFuture<bool> future, const QString& fileName);
    QFutureWatcher<QList<Ftp::FileInfo>> m_directoryWatcher;
    QString currentRemoteDir;
    QFutureWatcher<bool> m_downloadWatcher;
    void manageBatchDownload(const QList<QFuture<bool>>& futures);
};
#endif // MAINWINDOW_H
